<?php
session_start();
	include('../controller/functions.php');
	require_once '../controller/validation.php';
	User::connection();

$userArr	= array('admin','teacher','student');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
		print '		
			<script type="text/javascript">		
			window.location = "../login_r.php";
			</script>
			';

}


?>


<script type="text/javascript" src="../javascripts/jquery.js"></script>
	<script type="text/javascript" src="../javascripts/validation.js"></script>
    <script type="text/javascript" src="../javascripts/jquery-ui-1.7.2.custom.min.js"> </script>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="../images/fav.ico">
<link rel="icon" type="image/gif" href="../images/fav.ico">
<title>Create Section</title>

	<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
 	<link rel="stylesheet" href="../css/general.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/jquery-ui-1.7.2.custom.css" type="text/css" charset="utf-8" />
</head>
<body>
 <div id="page">
<div id="wrapper">      	
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- nav-->    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu_view.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
     <p> </p>
    
    <table width="100%" height="56">
     <tr>
       <td width="317" align="left"> 
        <? User::oras(); ?>
        </td>
            
       <td width="388" align="right"><? User::showPic(); ?></td>
       <td width="279">&nbsp;&nbsp;<? User::showUser(); ?>        </td>
       </tr>
   </table>
     
  
    </div>
    <div id="ex">
    </div>
    
      <p> </p>
   
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
        <!-- <div id="chef_ind">open chef --><!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>
  <!--</div>-->
  </div>
      
        
      <div id="content"> 
      <div class="desriptionHeader"> <!--open right-->
      <div id="container">
    
         <div class="post3"><h1>Administrator</h1> </div>
      
            <div class="desriptionHeader"> <!--open right-->
       <div class="postbg"><!--open booking -->
        <p> </p>
		
       <font color="#FF0000">
<strong>*Note: The schedule is every Mondays To Fridays only.</strong>
</font>
<p> </p>
		<?if( isset($_POST['send']) && (!validateSecName($_POST['secName']) || !validateRoomname($_POST['rName'])) ):?>
				<div id="error">
					<ul>
						<?if(!validateSecName($_POST['secName'])):?>
							<li><strong>Invalid Section Name:</strong> Please Select Section Name!</li>
						<?endif?>
                       
                        <?if(!validateRoomname($_POST['rName'])):?>
							<li><strong>Invalid RoomName:</strong> We want Firstname with more than 3 letters!</li>
						<?endif?>
					</ul>
				</div>
		<!--Registration for students -->
				
				<? elseif(isset($_POST['send'])):
				$oras1 = $_POST['oras1'];
				$oras2 = $_POST['oras2'];
				$oras3 = $_POST['oras3'];
				$oras4 = $_POST['oras4'];
				$oras5 = $_POST['oras5'];
				$oras6 = $_POST['oras6'];
				$oras7 = $_POST['oras7'];
				$oras8 = $_POST['oras8'];
				$oras9 = $_POST['oras9'];
				
				$oras10 = $_POST['oras10'];
				$oras11 = $_POST['oras11'];
				$oras12 = $_POST['oras12'];
				$oras13 = $_POST['oras13'];
				$oras14 = $_POST['oras14'];
				$oras15 = $_POST['oras15'];
				$oras16 = $_POST['oras16'];
				$oras17 = $_POST['oras17'];
				$oras18 = $_POST['oras18'];
					
				
				$qForTeacher = "SELECT u.fname, u.mname, u.lname FROM tbluser u
								WHERE u.userid = '$_POST[secAd]'";
				$qqForTeacher = mysql_query($qForTeacher);
				
				while($rowForTeacher = mysql_fetch_assoc($qqForTeacher)):
				$teacherFullName = $rowForTeacher['fname']." ".$rowForTeacher['mname'] ." ".$rowForTeacher['lname'];
				endwhile;
            		$query = sprintf("INSERT INTO `tblsection`(`sectionName`,`roomName`,`sectionAdviser`,`date`,`studentName`,`adviserName`,`yearLevel`) VALUES('$_POST[secName]','$_POST[rName]','$_POST[secAd]',NOW(),'none','$teacherFullName','$_POST[lvl]')");
	$res = @mysql_query($query);


		$query1 = sprintf("INSERT INTO `tblclass`(`sectionName`,`studentNumber`,`makabayan`,`makabayan1`,`makabayan2`,`makabayan3`,`makabayan4`,
						`filipino`,`english`,`math`,`science`,`adviserNumber`,`makaOras`,`maka1Oras`,`maka2Oras`,`maka3Oras`,`maka4Oras`,`filiOras`, 
						`englOras`,`mathOras`,`scieOras`,`makaOras1`,`maka1Oras1`,`maka2Oras1`,`maka3Oras1`,`maka4Oras1`,`filiOras1`,`englOras1`,`mathOras1`,`scieOras1`)
						VALUES('$_POST[secName]','none','$_POST[makAd]','$_POST[makAd1]','$_POST[makAd2]','$_POST[makAd3]','$_POST[makAd4]',
						'$_POST[filAd]','$_POST[engAd]','$_POST[mathAd]','$_POST[scieAd]','$_POST[secAd]','$oras7', '$oras9', '$oras11', '$oras13', '$oras15','$oras1',
						'$oras3','$oras5','$oras17','$oras8','$oras10','$oras12','$oras14','$oras16','$oras2','$oras4','$oras6','$oras18')");
	$res1 = @mysql_query($query1);

	
	
	if($res1 and $res){
		
		echo '<div id="okay">Done!</div>';
		echo '<div>
		
		Section Name: '.$_POST['secName'].'<br />
		Room Name: '.$_POST['rName'].' <br />
		Section Adviser: '.$teacherFullName.' <br />

		<br />
		
		 </div>
		 ';
		echo ' <a href="createSection.php"><input id="bbtn" type="button" name="Add Section" value="Add Section"></a>
		</div><!--close desc -->
   
        
         </div> <!--close container-->
   			
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 
 ';	
  echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';
	
	}
	else{
		echo '<div id="error">Error occured while saving!</div>
		
		
    	 
</div><!--close desc -->
   
        
         </div> <!--close container-->
   			
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 

		
		';
		
		 echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';
	}  
	
	if(!$res and !$res1)
		die("Error: ".mysql_error());
	else
		$r = $res . $res1;
		return $r;
			
            ?>
            
            <div id="error" class="valid">
					<ul>
						<li><strong>Congratulations!</strong> All fields are OK ;)</li>
					</ul>
				</div>	
		<?endif?>

		<form method="post" id="addSection" action="" >
			<div>
           
				<label for="secName">Section Name</label>
				<input id="secName" name="secName" type="text" />
				<span id="secNameInfo">Section Name</span>
			</div>
          
            <div>
            <label for="secAd">Section Adviser</label>
            <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher'
	
											";
											
									$select		= 	"<select name='secAd'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									$select	   .= 	"</select>";
								
									$secAdvName	= $select;
									print($secAdvName);
			
			?> 
          <a href="regTeachers.php">Add Teacher</a></div>
            <div>
            
				<label for="rName">Room Name</label>
				<input id="rName" name="rName" type="text" />
				<span id="rNameInfo">Room Name</span>
			</div>
      <div>  
           <label for="yearLevel">Year Level</label>
			<input type="radio" name="lvl" value="1" />
       	1st Year <p> </p>
       	<input type="radio" name="lvl" value="2"  />
       	2nd Year <p> </p>
        <input type="radio" name="lvl" value="3" />
       	3rd Year <p> </p>
       	<input type="radio" name="lvl" value="4"  />
       	4th Year <p> </p>
        </div>
        
         
           
            <div>
				<label for="filAd">Filipino Teacher</label>
			    <input type="text" id="oras1" name="oras1" class="time3" size="10" value="<? print $oras1; ?>" /> &nbsp;To&nbsp;
                <input type="text" id="oras2" name="oras2" class="time4" size="10" value="<? print $oras2; ?>" />
				 <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher' 
												AND subject1 = 'Filipino' OR subject2 = 'Filipino' OR 
												subject3 = 'Filipino' OR subject4 = 'Filipino' OR subject5 = 'Filipino';
	
											";
											
									$select		= 	"<select name='filAd'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									$select	   .= 	"</select>";
								
									$secFilName	= $select;
									print($secFilName);
			
			?> 
				<span id="filAdInfo">Filipino Teacher</span>
                </div>
            
            <div>
				<label for="engAd">English Teacher</label>
             	<input type="text" class="time3" size="10" name="oras3" id="oras3" value="<? print $oras3; ?>" />  &nbsp;To&nbsp
                <input type="text" class="time4" size="10" name="oras4" id="oras4" value="<? print $oras4; ?>" />
               <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher' 
												AND subject1 = 'English' OR subject2 = 'English' OR 
												subject3 = 'English' OR subject4 = 'English' OR subject5 = 'English';
	
											";
											
									$select		= 	"<select name='engAd'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									$select	   .= 	"</select>";
								
									$secengAdName	= $select;
									print($secengAdName);
			
			?> 
				<span id="engAdInfo">English Teacher</span>
			</div>
              
            <div>           
				<label for="mathAd">Math Teacher</label>
		     	<input type="text" class="time3" size="10" name="oras5" id="oras5" value="<? print $oras5; ?>" />  &nbsp;To&nbsp
                <input type="text" class="time4" size="10" name="oras6" id="oras6" value="<? print $oras6; ?>" />
				
                   <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher' 
												AND subject1 = 'Math' OR subject2 = 'Math' OR 
												subject3 = 'Math' OR subject4 = 'Mah' OR subject5 = 'Math';
	
											";
											
									$select		= 	"<select name='mathAd'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									$select	   .= 	"</select>";
								
									$secengAdName	= $select;
									print($secengAdName);
			
			?> 
				<span id="mathAdInfo">Math Teacher</span>
			</div>
            <div>
           
		 	    <label for="makAd">Makabayan Teacher</label>
                <input type="text" class="time3" size="10" name="oras7" id="oras7" value="<? print $oras7; ?>" />  &nbsp;To&nbsp
                <input type="text" class="time4" size="10" name="oras8" id="oras8" value="<? print $oras8; ?>" />
			
                        <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher' 
												AND subject1 = 'Makabayan' OR subject2 = 'Makabayan' OR 
												subject3 = 'Makabayan' OR subject4 = 'Makabayan' OR subject5 = 'Makabayan';
	
											";
											
									$select		= 	"<select name='makAd'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									
									$select	   .= 	"</select>";
								
									$secengAdName	= $select;
									print($secengAdName);
				
			
			?> 
				<span id="macAdInfo">Makabayan Teacher</span>
			</div>
            <div>
           
				<label for="makAd1">Makabayan1 Teacher</label>
                <input type="text" class="time3" size="10" name="oras9" id="oras9" value="<? print $oras9; ?>" />  &nbsp;To&nbsp
                <input type="text" class="time4" size="10" name="oras10" id="oras10" value="<? print $oras10; ?>" />
				
                           <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher' 
												AND subject1 = 'Makabayan1' OR subject2 = 'Makabaya1' OR 
												subject3 = 'Makabayan1' OR subject4 = 'Makabayan1' OR subject5 = 'Makabayan1';
	
											";
											
									$select		= 	"<select name='makAd1'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									
									$select	   .= 	"</select>";
								
									$secengAdName	= $select;
									print($secengAdName);
				
			
			?> 
				<span id="makAdInfo1">Makabayan1 Teacher</span>
			</div>
             <div>
           
				<label for="makAd2">Makabayan2 Teacher</label>
				<input type="text" class="time3" size="10" name="oras11" id="oras11" value="<? print $oras11; ?>" />  &nbsp;To&nbsp
                <input type="text" class="time4" size="10" name="oras12" id="oras12" value="<? print $oras12; ?>" />
			
                      <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher' 
												AND subject1 = 'Makabayan2' OR subject2 = 'Makabaya2' OR 
												subject3 = 'Makabayan2' OR subject4 = 'Makabayan2' OR subject5 = 'Makabayan2';
	
											";
											
									$select		= 	"<select name='makAd2'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									
									$select	   .= 	"</select>";
								
									$secengAdName	= $select;
									print($secengAdName);
				
			
			?> 
				<span id="makAdInfo2">Makabayan2 Teacher</span>
			</div>
              <div>
           
				<label for="makAd3">Makabayan3 Teacher</label>
       			<input type="text" class="time3" size="10" name="oras13" id="oras13" value="<? print $oras13; ?>" />  &nbsp;To&nbsp
                <input type="text" class="time4" size="10" name="oras14" id="oras14" value="<? print $oras14; ?>" />
				
                 <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher' 
												AND subject1 = 'Makabayan3' OR subject2 = 'Makabaya3' OR 
												subject3 = 'Makabayan3' OR subject4 = 'Makabayan3' OR subject5 = 'Makabayan3';
	
											";
											
									$select		= 	"<select name='makAd3'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									
									$select	   .= 	"</select>";
								
									$secengAdName	= $select;
									print($secengAdName);
				
			
			?> 
				<span id="makAdInfo3">Makabayan3 Teacher</span>
			</div>
              <div>
           
				<label for="makAd4">Makabayan4 Teacher</label>
                <input type="text" class="time3" size="10" name="oras15" id="oras15" value="<? print $oras15; ?>" />  &nbsp;To&nbsp
                <input type="text" class="time4" size="10" name="oras16" id="oras16" value="<? print $oras16; ?>" />
				  <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher' 
												AND subject1 = 'Makabayan4' OR subject2 = 'Makabaya4' OR 
												subject3 = 'Makabayan4' OR subject4 = 'Makabayan4' OR subject5 = 'Makabayan4';
	
											";
											
									$select		= 	"<select name='makAd4'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									
									$select	   .= 	"</select>";
								
									$secengAdName	= $select;
									print($secengAdName);
				
			
			?> 
				<span id="makAdInfo4">Makabayan4 Teacher</span>
			</div>
 
         
            <div>           
		  	    <label for="scieAd">Science Teacher</label>
           		<input type="text" class="time3" size="10" name="oras17" id="oras17" value="<? print $oras17; ?>" />  &nbsp;To&nbsp
                <input type="text" class="time4" size="10" name="oras18" id="oras18" value="<? print $oras18; ?>" />
				
                  <? 
			
				$q	= 		"	
												SELECT 	u.fname, u.lname, u.userid
												FROM 	tbluser u WHERE u.user_type = 'teacher' 
												AND subject1 = 'Science' OR subject2 = 'Science' OR 
												subject3 = 'Science' OR subject4 = 'Science' OR subject5 = 'Science';
	
											";
											
									$select		= 	"<select name='scieAd'>";			
									$temp 	= mysql_query($q);	
									while ($selAd	= mysql_fetch_assoc($temp)) {	
										$teacherName = 	$selAd['fname']." ".$selAd['lname'];
										$select .= "<option value = '".$selAd['userid']."'>".$teacherName."</option>";
									}
									
									$select	   .= 	"</select>";
								
									$secengAdName	= $select;
									print($secengAdName);
				
			
			?> 
				<span id="scieAdInfo">Science Teacher</span>
			</div>
        	<div>
				<input id="send" name="send" type="submit" value="Send" />
			</div>
		</form>
   </div><!--close desc -->
   
        
         </div> <!--close container-->
   			
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 <?php 
	  echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';	
	  ?>

    </div><!-- close body-->
</div><!-- close page-->
</body>
</html>



